﻿namespace PropertyManagementSystemAPI.FreeSqlSetUp
{
    public static class FreeSqlSetup
    {
        public static void AppFreeSQLSetup(this IServiceCollection services, IConfiguration configuration)
        {
            //freesql
            Func<IServiceProvider, IFreeSql> fsqlFactory = r =>
            {
                IFreeSql fsql = new FreeSql.FreeSqlBuilder()
                    .UseConnectionString(FreeSql.DataType.MySql, configuration.GetConnectionString("conStr"))
                    .UseMonitorCommand(cmd => Console.WriteLine($"Sql：{cmd.CommandText}"))//监听SQL语句
                    .UseAutoSyncStructure(true) //自动同步实体结构到数据库，FreeSql不会扫描程序集，只有CRUD时才会生成表。
                    .Build();
                return fsql;
            };
            services.AddSingleton<IFreeSql>(fsqlFactory);
        }
    }
}

